
<?php
$baner = Panel::model()->findAll(
        array(
            'condition' => ' `flag`=1 and `type`=0 and `dateCreate`<= CURDATE() and `dateEpend`>=CURDATE() order by vitri ASC',
            'limit' => 30,
        )
);
if (!empty($baner)) {
    $lan = 0;
    $right = '';
    $flag = 0;
    $dem = 0;
    $dem1 = 0;
    ?>
    <div id="ad_global_below_navbar">
        <?php
        foreach ($baner as $b) {

            $h = 0;

            $lan = $lan + 1;

            if ($lan < 2) {
                if ($b->kieu == 0) {
                    $h = 396;
                } elseif ($b->kieu == 1) {
                    $h = 792;
                    $flag = 1;
                }
                ?>
                <div class="rightleftads" style="position: absolute; top: 74px; left: 10px; z-index: 1; display: block;width: 180px">
                    <a href="<?php echo $b->url; ?>" target="_blank" rel="nofollow"><img title="<?php echo $b->name; ?>" src="<?php echo Yii::app()->request->baseUrl . '/upload/quangcao/' . $b->photo; ?>" width="180" height="<?php echo $h; ?>" alt="<?php echo $b->name; ?>" border="0"></a>
                    <?php
                } elseif ($lan < 3) {
                    if ($flag < 1) {
                        ?>
                        <a href="<?php echo $b->url; ?>" target="_blank" rel="nofollow"><img title="<?php echo $b->name; ?>" src="<?php echo Yii::app()->request->baseUrl . '/upload/quangcao/' . $b->photo; ?>" width="180" height="396" alt="<?php echo $b->name; ?>" border="0"></a>
                    </div>
                    <?php
                } else {
                    ?>
                </div>

                <?php
                    $flag = 2;
            if ($b->kieu == 0) {
                $dem = $dem + 1;
                $h = 264;
                if ($dem < 2) {
                    $right = $right . '<li><a href="' . $b->url . '" target="_blank" rel="nofollow"><img class="aut" title="' . $b->name . '" src="' . Yii::app()->request->baseUrl . '/upload/quangcao/' . $b->photo . '" width="180" height="' . $h . '"  border="0"></a>';
                } elseif ($dem < 3) {
                    $right = $right . '<a href="' . $b->url . '" target="_blank" rel="nofollow"><img class="aut" title="' . $b->name . '" src="' . Yii::app()->request->baseUrl . '/upload/quangcao/' . $b->photo . '" width="180" height="' . $h . '"  border="0"></a>';
                } elseif ($dem > 2) {
                    $right = $right . '<a href="' . $b->url . '" target="_blank" rel="nofollow"><img class="aut" title="' . $b->name . '" src="' . Yii::app()->request->baseUrl . '/upload/quangcao/' . $b->photo . '" width="180" height="' . $h . '"  border="0"></a></li>';
                    $dem = 0;
                }
            } elseif ($b->kieu == 2) {
                
                $h = 264 + 266;
                if($dem==1){
                    $dem = 0;
                    $right = $right . '<a href="' . $b->url . '" target="_blank" rel="nofollow"><img class="aut" title="' . $b->name . '" src="' . Yii::app()->request->baseUrl . '/upload/quangcao/' . $b->photo . '" width="180" height="' . $h . '"  border="0"></a></li>';
                }  else {
                    $dem = 3;
                    $right = $right . '<li><a href="' . $b->url . '" target="_blank" rel="nofollow"><img class="aut" title="' . $b->name . '" src="' . Yii::app()->request->baseUrl . '/upload/quangcao/' . $b->photo . '" width="180" height="' . $h . '"  border="0"></a>';
                }
                
            } elseif ($b->kieu == 3) {
                $h = 792;
                $right = $right . '<li><a href="' . $b->url . '" target="_blank" rel="nofollow"><img class="aut" title="' . $b->name . '" src="' . Yii::app()->request->baseUrl . '/upload/quangcao/' . $b->photo . '" width="180" height="' . $h . '"  border="0"></a></li>';
            }
            }
            ?>


            <?php
        } else {
            $flag = 2;
            if ($b->kieu == 0) {
                $dem = $dem + 1;
                $h = 264;
                if ($dem < 2) {
                    $right = $right . '<li><a href="' . $b->url . '" target="_blank" rel="nofollow"><img class="aut" title="' . $b->name . '" src="' . Yii::app()->request->baseUrl . '/upload/quangcao/' . $b->photo . '" width="180" height="' . $h . '"  border="0"></a>';
                } elseif ($dem < 3) {
                    $right = $right . '<a href="' . $b->url . '" target="_blank" rel="nofollow"><img class="aut" title="' . $b->name . '" src="' . Yii::app()->request->baseUrl . '/upload/quangcao/' . $b->photo . '" width="180" height="' . $h . '"  border="0"></a>';
                } elseif ($dem > 2) {
                    $right = $right . '<a href="' . $b->url . '" target="_blank" rel="nofollow"><img class="aut" title="' . $b->name . '" src="' . Yii::app()->request->baseUrl . '/upload/quangcao/' . $b->photo . '" width="180" height="' . $h . '"  border="0"></a></li>';
                    $dem = 0;
                }
            } elseif ($b->kieu == 2) {
                
                $h = 264 + 266;
                if($dem==1){
                    $dem = 0;
                    $right = $right . '<a href="' . $b->url . '" target="_blank" rel="nofollow"><img class="aut" title="' . $b->name . '" src="' . Yii::app()->request->baseUrl . '/upload/quangcao/' . $b->photo . '" width="180" height="' . $h . '"  border="0"></a></li>';
                }  else {
                    $dem = 3;
                    $right = $right . '<li><a href="' . $b->url . '" target="_blank" rel="nofollow"><img class="aut" title="' . $b->name . '" src="' . Yii::app()->request->baseUrl . '/upload/quangcao/' . $b->photo . '" width="180" height="' . $h . '"  border="0"></a>';
                }
                
            } elseif ($b->kieu == 3) {
                $h = 792;
                $right = $right . '<li><a href="' . $b->url . '" target="_blank" rel="nofollow"><img class="aut" title="' . $b->name . '" src="' . Yii::app()->request->baseUrl . '/upload/quangcao/' . $b->photo . '" width="180" height="' . $h . '"  border="0"></a></li>';
            }
        }
    }
    if ($flag > 1) {
        ?>
        <div class="rightleftads" style="position: absolute; top: 74px; right: 37px; z-index: 1; display: block;width: 180px">

            <ul id="mycarousel1" class="jcarousel-skin-chacha">
        <?php echo $right; ?>

            </ul>
        </div>
                <?php
            }
        }
        ?>

<script type="text/javascript">
    <!--
               function rightleftads() {
        var $winwidth = $(window).width();
        //if (1210 >= $(window).width()) {
        // $('.rightleftads').hide();
        //}
        //else {
        // $('.rightleftads').show();
        //}

    }
    $(window).resize(function() {
        //rightleftads();
    });
    //rightleftads();
//-->
</script></div>

